package com.zhumei.keyscale.ui;

import me.jingbin.bymvvm.base.*;
import com.zhumei.keyscale.databinding.*;
import com.zhumei.keyscale.entity.*;
import com.zhumei.keyscale.adapter.*;
import androidx.databinding.*;
import android.text.*;
import com.zhumei.keyscale.net.*;
import com.zhumei.keyscale.entity.vo.*;
import retrofit2.*;
import android.content.*;
import me.jingbin.bymvvm.utils.*;
import org.json.*;
import java.util.*;
import okhttp3.*;
import android.app.*;
import android.os.*;
import androidx.recyclerview.widget.*;
import com.blankj.utilcode.util.*;
import com.zhumei.keyscale.weight.*;
import android.view.*;
import com.chad.library.adapter.base.*;

public class SelectShopActivity extends BaseActivity<NoViewModel, ActivitySelectShopBinding>
{
    private List<CommonModule> datas;
    int defaultPos;
    private ShopAdapter shopAdapter;
    int type;
    
    public SelectShopActivity() {
        this.datas = new ArrayList<CommonModule>();
        this.defaultPos = 0;
        this.type = 0;
    }
    
    private void getShops(final String s) {
        if (TextUtils.isEmpty((CharSequence)s)) {
            LogUtils.d("phone is null...");
            return;
        }
        HttpManager.INSTANCE.queryShopIds(s, (Callback<BaseResponse<List<QueryShops>>>)new Callback<BaseResponse<List<QueryShops>>>() {
            public void onFailure(final Call<BaseResponse<List<QueryShops>>> call, final Throwable t) {
                MyToast.showShort(t.getMessage());
            }
            
            public void onResponse(final Call<BaseResponse<List<QueryShops>>> call, final Response<BaseResponse<List<QueryShops>>> response) {
                if (ObjectUtils.isEmpty(response)) {
                    return;
                }
                if (ObjectUtils.isEmpty(response.body())) {
                    return;
                }
                final BaseResponse baseResponse = (BaseResponse)response.body();
                final String resMsg = baseResponse.getResMsg();
                if (baseResponse.getResCode() == 0) {
                    final List<QueryShops> newData = baseResponse.getData();
                    if (newData.size() != 1 || SelectShopActivity.this.type == 1) {
                        ((BaseQuickAdapter<QueryShops, K>)SelectShopActivity.this.shopAdapter).setNewData(newData);
                        return;
                    }
                    final Intent intent = new Intent((Context)SelectShopActivity.this, (Class)MainActivity.class);
                    if (!newData.isEmpty()) {
                        final QueryShops queryShops = newData.get(0);
                        MmkvUtils.getInstance().putEntity("queryShops", (Object)queryShops);
                        if (!TextUtils.isEmpty((CharSequence)queryShops.getMerchantId())) {
                            final HashMap<String, String> hashMap = new HashMap<String, String>();
                            hashMap.put("shopId", queryShops.getShopId());
                            hashMap.put("merchantId", queryShops.getMerchantId());
                            HttpManager.INSTANCE.saveLoginRecord(RequestBody.create(MediaType.parse("application/json; charset=utf-8"), new JSONObject((Map)hashMap).toString()), (Callback<BaseResponse<Object>>)new Callback<BaseResponse<Object>>() {
                                public void onFailure(final Call<BaseResponse<Object>> call, final Throwable t) {
                                }
                                
                                public void onResponse(final Call<BaseResponse<Object>> call, final Response<BaseResponse<Object>> response) {
                                }
                            });
                        }
                        SelectShopActivity.this.startActivity(intent);
                    }
                }
                else {
                    MyToast.showShort(resMsg);
                }
            }
        });
    }
    
    protected Activity getActivity() {
        return (Activity)this;
    }
    
    protected void onCreate(final Bundle bundle) {
        super.onCreate(bundle);
        this.setContentView(2131427361);
        this.showContentView();
        this.getIntent().getStringExtra("jump");
        final String string = MmkvUtils.getInstance().getString("phone");
        this.type = this.getIntent().getIntExtra("type", 0);
        ((ActivitySelectShopBinding)this.bindingView).rvShop.setLayoutManager((RecyclerView.LayoutManager)new GridLayoutManager((Context)this, 3));
        this.shopAdapter = new ShopAdapter(null);
        ((ActivitySelectShopBinding)this.bindingView).rvShop.setAdapter((RecyclerView.Adapter)this.shopAdapter);
        this.datas.clear();
        if (NetworkUtils.isConnected()) {
            this.getShops(string);
        }
        else {
            this.startActivity(new Intent((Context)this, (Class)MainActivity.class));
        }
        SerialPortUtil.getSerialPortUtil().setKeyboardsInterface((SerialPortUtil.KeyboardsInterface)new SerialPortUtil.KeyboardsInterface() {
            @Override
            public void vaues(final String s) {
                final StringBuilder sb = new StringBuilder();
                sb.append("values111  ");
                sb.append(s);
                LogUtils.d(sb.toString());
                if (SelectShopActivity.this.defaultPos <= 0) {
                    SelectShopActivity.this.defaultPos = 0;
                }
                if (s.equals("\u53bb\u76ae")) {
                    final SelectShopActivity this$0 = SelectShopActivity.this;
                    --this$0.defaultPos;
                    if (SelectShopActivity.this.defaultPos <= 0) {
                        SelectShopActivity.this.defaultPos = 0;
                    }
                    if (SelectShopActivity.this.defaultPos % 15 == 0) {
                        ((ActivitySelectShopBinding)SelectShopActivity.this.bindingView).rvShop.smoothScrollBy(0, -400);
                    }
                    SelectShopActivity.this.shopAdapter.setSelPos(SelectShopActivity.this.defaultPos);
                }
                if ("\u7f6e\u96f6".equals(s)) {
                    final SelectShopActivity this$2 = SelectShopActivity.this;
                    ++this$2.defaultPos;
                    if (SelectShopActivity.this.defaultPos >= ((BaseQuickAdapter<QueryShops, K>)SelectShopActivity.this.shopAdapter).getData().size()) {
                        final SelectShopActivity this$3 = SelectShopActivity.this;
                        this$3.defaultPos = this$3.shopAdapter.getData().size() - 1;
                    }
                    if (SelectShopActivity.this.defaultPos % 15 == 0) {
                        ((ActivitySelectShopBinding)SelectShopActivity.this.bindingView).rvShop.smoothScrollBy(0, 400);
                    }
                    SelectShopActivity.this.shopAdapter.setSelPos(SelectShopActivity.this.defaultPos);
                }
                if (s.equals("\u8fd4\u56de")) {
                    final Intent intent = new Intent((Context)SelectShopActivity.this, (Class)LoginActivity.class);
                    intent.putExtra("type", 1);
                    SelectShopActivity.this.startActivity(intent);
                }
                if ("\u786e\u8ba4".equals(s)) {
                    final Intent intent2 = new Intent((Context)SelectShopActivity.this, (Class)MainActivity.class);
                    if (SelectShopActivity.this.shopAdapter != null && !((BaseQuickAdapter<QueryShops, K>)SelectShopActivity.this.shopAdapter).getData().isEmpty()) {
                        final QueryShops queryShops = ((BaseQuickAdapter<QueryShops, K>)SelectShopActivity.this.shopAdapter).getData().get(SelectShopActivity.this.shopAdapter.getDefaultFocus());
                        MmkvUtils.getInstance().putEntity("queryShops", (Object)queryShops);
                        if (!TextUtils.isEmpty((CharSequence)queryShops.getMerchantId())) {
                            final HashMap<String, String> hashMap = new HashMap<String, String>();
                            hashMap.put("shopId", queryShops.getShopId());
                            hashMap.put("merchantId", queryShops.getMerchantId());
                            HttpManager.INSTANCE.saveLoginRecord(RequestBody.create(MediaType.parse("application/json; charset=utf-8"), new JSONObject((Map)hashMap).toString()), (Callback<BaseResponse<Object>>)new Callback<BaseResponse<Object>>() {
                                public void onFailure(final Call<BaseResponse<Object>> call, final Throwable t) {
                                }
                                
                                public void onResponse(final Call<BaseResponse<Object>> call, final Response<BaseResponse<Object>> response) {
                                }
                            });
                        }
                    }
                    SelectShopActivity.this.startActivity(intent2);
                }
            }
        });
    }
    
    public void setCacheViewFromContent(final View view) {
        final StringBuilder sb = new StringBuilder();
        sb.append("focusView ");
        sb.append(view);
        LogUtils.d(sb.toString());
    }
    
    public void setmCacheViewFromTab(final View view) {
        final StringBuilder sb = new StringBuilder();
        sb.append("focusView ");
        sb.append(view);
        LogUtils.d(sb.toString());
    }
}
